$(function(){
    var getParams = getArgs();
    window.currentHotel = getParams.hotel;
    var shopkeeperContainer = $('#doc-body .modal-body');
    var qrShareId = getParams.specialId;
    var symbols = $('#doc').data('symbols');
    toggleLoading(true);
    ajaxRequest('/Home/Hotel/special', {
        hotel:window.currentHotel,
    }, 'POST', function (data) {
        shopkeeperContainer.html('');
        var info =data.data,newInfoId = [],isactiveInfo = [];        
        var hotelName = info.hotelName;              
        if(hotelName != ''){
            $('.zhangGui-hotel h3').html(hotelName);
        };
        if(info.minPrice != ''){
            $('.zhangGui-bind').text(symbols+lang('roomReservation')+ info.minPrice+lang('qi'));
        }
        for(var i=0;i<info.specials.length;i++){
            if(info.specials[i].isactive == 1){
                isactiveInfo.unshift(info.specials[i]);
            }else{
                isactiveInfo.push(info.specials[i]); 
            }          
        } ;            
        if(qrShareId != ''){
            for(var i=0;i<isactiveInfo.length;i++){
                if(isactiveInfo[i].specialId == qrShareId){
                    newInfoId.unshift(isactiveInfo[i]);
                }else{
                    newInfoId.push(isactiveInfo[i]);
                }         
            } 
            isactiveInfo = newInfoId;
        }; 
        var ShopkeeperHTML = '';     
        var arrUrl = []; 
        var newUrl = [];
        var templateShopkeeper = $($('#templateShopkeeper').clone().html());        
        for(var i=0;i<isactiveInfo.length;i++){
            templateShopkeeper.find('.Shopkeeper-cover').css('background', 'url('+isactiveInfo[i].specialImageUrl+')').css('background-size','100% 100%').attr('data-url',isactiveInfo[i].specialImageUrl);
            templateShopkeeper.find('.Shopkeeper-dosc').html(isactiveInfo[i].special);
            arrUrl.push(isactiveInfo[i].specialImageUrl);
            ShopkeeperHTML += templateShopkeeper.prop('outerHTML');        
        };
        shopkeeperContainer.append(ShopkeeperHTML);   
        $('#doc-body .modal-body').on('click','li',function(){
            var URL = $(this).find('p').attr('data-url');
            var newUrl = [];
            for(var i=0 ;i<arrUrl.length;i++){
                if(arrUrl[i] == URL){
                   newUrl.unshift(arrUrl[i]);
                }else{
                    newUrl.push (arrUrl[i]);
                }
            }
            window.location.href = '/Home/BookPage/indexpic?hotel=' + window.currentHotel+'&pic='+newUrl.join(',');
        });
        toggleLoading(false);
    },function (error) {
        toggleLoading(false);
    });
    var originalHref = $('#doc-header .zhangGui-header a').attr('href');
    $('.zhangGui-bind').attr('href', originalHref + '?hotel=' + window.currentHotel+'&name=Bind');
    $('#doc-body .zhangGui-wantBind').attr('href', originalHref + '?hotel=' + window.currentHotel+'&name=Bind');

});

